package com.cn.lyl.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.Page;
import com.cn.lyl.model.UserModel;
import com.cn.lyl.service.UserService;
import com.cn.lyl.service.impl.UserServiceImpl;
import com.cn.lyl.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/user/findAll")
public class FindAllServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //        1.得到前端传递过来的数据
        String username = req.getParameter("username");
        String start = req.getParameter("start");
        String end = req.getParameter("end");
        String phone = req.getParameter("mobile");
        String sex = req.getParameter("gender");
        String hobby = req.getParameter("hobby");
        UserModel userModel = new UserModel();
        userModel.setUsername(username);
        Page page=new Page();
        page.setPageCurr(Tool.curr(req.getParameter("curPage")));
        page.setPageSize(Tool.size(req.getParameter("pageSize")));
        userModel.setPage(page);
        userModel.setStart(start);
        userModel.setEnd(end);
        userModel.setMobile(phone);
        userModel.setGender(sex);
        userModel.setHobby(hobby);
        UserService userService = new UserServiceImpl();
        List<UserModel> allUser = userService.findAllUser(userModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",allUser);
        resp.getWriter().print(jsonObject);
    }
}
